package cn.smile.commons.enums.base;

import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * @author smile
 */
@Getter
public enum TableOrderEnum {
    /**
     * 升序
     */
    ASC("ASC"),
    /**
     * 降序
     */
    DESC("DESC"),
    /**
     * 未知字段
     */
    NULL(null);
    private final String code;

    TableOrderEnum(String code) {
        this.code = code;
    }

    public static TableOrderEnum get(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return NULL;
        }
        code = code.toUpperCase();
        for (TableOrderEnum typeEnum : TableOrderEnum.values()) {
            if (code.equals(typeEnum.code)) {
                return typeEnum;
            }
        }
        return NULL;
    }
}
